package com.rong.shop.config.aop;

import com.rong.shop.utils.RongUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class TimerAspect {

    @Around("execution(* com.rong.shop.service.impl.*.*(..))")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {

        long start = System.currentTimeMillis();
        Object proceed = pjp.proceed();         // 调用service.impl.*.* 执行方法
        long end = System.currentTimeMillis();
        long result = end - start;
        RongUtils.print(pjp.getTarget().getClass().getName());  // 获取调用的类名
        RongUtils.print(pjp.getSignature().getName() + "耗时：" + result + "ms");          // 获取调用的方法名

        return proceed;

    }
}
